package com.wentao.thisCommon.model;

import org.springframework.beans.BeanUtils;

import javax.validation.Valid;

public class BaseEntity<T> extends BaseContent {

    public BaseEntity() {
    }

    public BaseEntity(T t, RequestBase<?> entity) {
        BeanUtils.copyProperties(entity.getBody(), t);
        this.setAppId(entity.getAppId());
        this.setFunc(entity.getFunc());
        this.setMethod(entity.getMethod());
        this.setOth(entity.getOth());
        this.setToken(entity.getToken());
        this.setUserId(entity.getUserId());
        this.setVersion(entity.getVersion());

        this.setBody(t);
        this.setInnerBody(t);
    }

    public BaseEntity(T t, BaseEntity<?> entity) {
        BeanUtils.copyProperties(entity.getBody(), t);
        this.setAppId(entity.getAppId());
        this.setFunc(entity.getFunc());
        this.setMethod(entity.getMethod());
        this.setOth(entity.getOth());
        this.setToken(entity.getToken());
        this.setUserId(entity.getUserId());
        this.setVersion(entity.getVersion());

        this.setBody(t);
        this.setInnerBody(t);
    }

    @Valid
    private T body;

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
        this.setInnerBody(body);
    }

}
